<?php require_once 'inc/header.php'; ?>
<?php

if ($friendCount = $db->q1('SELECT COUNT(*) FROM friends WHERE user_fbid = ?', $_SESSION['me']['fbid'])) {
	$factNumber = mt_rand(1, 4);
	switch ($factNumber) {
		case 1:
			$randomFact = "You have $friendCount friends on Facebook! <a href='//apps.facebook.com/bingome/likes.php' target='_top'>Compare Likes with your friends!</a>";
			break;
		case 2:
			$postCount = $db->q1('SELECT COUNT(*) FROM posts WHERE user_fbid = ?', $_SESSION['me']['fbid']);
			$earliestDate = $db->q1("SELECT DATE_FORMAT(MIN(dt), '%M %e, %Y') FROM posts WHERE user_fbid = ?", $_SESSION['me']['fbid']);
			$randomFact = sprintf("You have made %d posts on Facebook since %s! <a href='//apps.facebook.com/bingome/posts.php' target='_top'>Find out more about these posts!</a>", $postCount, $earliestDate);
			break;
		case 3:
			$likeCount = $db->q1('SELECT COUNT(*) FROM likes WHERE user_fbid = ?', $_SESSION['me']['fbid']);
			$randomFact = "You have made $likeCount likes on Facebook! <a href='//apps.facebook.com/bingome/likes.php' target='_top'>Discover the common things you and your friends like!</a>";
			break;
		case 4:
			$checkinCount = $db->q1('SELECT COUNT(*) FROM checkins WHERE fbid = ?', $_SESSION['me']['fbid']);
			$randomFact = "You have made $checkinCount check-ins on Facebook! <a href='//apps.facebook.com/bingome/checkins.php' target='_top'>Check out the popular locations your friends are hanging out at!</a>";
			break;
	}
} else {
	$friends = $fb->api('/me/friends');
	$friendCount = count($friends['data']);
	$randomFact = "You have $friendCount friends on Facebook! <a href='//apps.facebook.com/bingome/likes.php' target='_top'>Compare Likes with your friends!</a>";
}

?>
<div id="didyouknow">
	<a href="//apps.facebook.com/bingome/" target='_top'><img src="images/dyk.png"></a>
	<p><?php echo $randomFact; ?></p>
</div>
<?php require_once 'inc/footer.php'; ?>
